package com.qumitech.visualnovel.controller.rest.novel;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.qumitech.visualnovel.model.common.BaseResponse;
import com.qumitech.visualnovel.service.novel.AuthorService;
import com.qumitech.visualnovel.model.dto.AuthorQueryDTO;
import com.qumitech.visualnovel.model.dto.AuthorUpdateDTO;
import com.qumitech.visualnovel.model.dto.AuthorPolicyQueryDTO;
import com.qumitech.visualnovel.model.dto.AuthorPolicyAddDTO;
import com.qumitech.visualnovel.model.dto.AuthorPolicyUpdateDTO;
import com.qumitech.visualnovel.model.dto.AuthorIntroDTO;

@RestController
@Api(value = "作者管理", description = "作者管理")
public class AuthorRest {
    @Autowired
    private AuthorService authorService;

    @ApiOperation(value = "查询作者列表", notes = "查询作者列表")
    @GetMapping("/api/author/list")
    public BaseResponse listAuthor(AuthorQueryDTO param) {
        return authorService.listAuthor(param);
    }

    @ApiOperation(value = "查询作者信息", notes = "查询作者信息")
    @GetMapping("/api/author/detail")
    public BaseResponse detailAuthor(@RequestParam(value="uid", required=true) Integer uid) {
        return authorService.detailAuthor(uid);
    }

    @ApiOperation(value = "修改作者信息", notes = "修改作者信息")
    @PostMapping("/api/author")
    public BaseResponse updateAuthor(@RequestBody AuthorUpdateDTO param) {
        return authorService.updateAuthor(param);
    }

    @ApiOperation(value = "查询作者简介", notes = "查询作者简介")
    @GetMapping("/api/author/intro/{book_id}")
    public BaseResponse getAuthorIntro(@PathVariable(name="book_id") Long bookId) {
        return authorService.getAuthorIntro(bookId);
    }

    @ApiOperation(value = "修改作者简介", notes = "修改作者简介")
    @PutMapping("/api/author/intro")
    public BaseResponse updateAuthorIntro(@RequestBody AuthorIntroDTO body) {
        return authorService.updateAuthorIntro(body);
    }

    @ApiOperation(value = "创建签约政策", notes = "创建签约政策")
    @PutMapping("/api/author/policy")
    public BaseResponse addAuthorPolicy(@RequestBody AuthorPolicyAddDTO param) {
        return authorService.addAuthorPolicy(param);
    }

    @ApiOperation(value = "修改签约政策", notes = "修改签约政策")
    @PostMapping("/api/author/policy")
    public BaseResponse updateAuthorPolicy(@RequestBody AuthorPolicyUpdateDTO param) {
        return authorService.updateAuthorPolicy(param);
    }

    @ApiOperation(value = "删除签约政策", notes = "删除签约政策")
    @DeleteMapping("/api/author/policy/{id}")
    public BaseResponse delAuthorPolicy(@PathVariable("id") Long id) {
        return authorService.delAuthorPolicy(id);
    }

    @ApiOperation(value = "查询签约政策列表", notes = "查询签约政策列表")
    @GetMapping("/api/author/policy/list")
    public BaseResponse listAuthorPolicy(AuthorPolicyQueryDTO param) {
        return authorService.listAuthorPolicy(param);
    }
}
